package com.jiang.jetpackdemo.utils

import android.widget.ImageView
import androidx.lifecycle.MutableLiveData
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.jiang.jetpackdemo.R

/**
 *
 * @ProjectName:    JetpackDemo
 * @ClassName:      ExtensionFunction
 * @Description:     java类作用描述
 * @Author:         江
 * @CreateDate:     2020/6/20 10:29
 */


fun <T> MutableList<T>.addAndChange(
    imgInfo: T,
    sizeOfLiveDataList: MutableLiveData<Int>
) {
    this.add(imgInfo)
    sizeOfLiveDataList.postValue(this.size)
}

fun <T> MutableList<T>.addAllAndChange(
    collection: Collection<T>,
    sizeOfLiveDataList: MutableLiveData<Int>
) {
    this.addAll(collection)
    sizeOfLiveDataList.postValue(this?.size)
}

fun ImageView.loadPicFromNet(url: String) {
    Glide.with(this)
        .load(url)
        .placeholder(R.drawable.ic_sync)
        .error(R.drawable.ic_error)
        .timeout(6000)
        .transition(DrawableTransitionOptions.withCrossFade())
        .into(this)
}

